package com.zjitc.config;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.google.gson.Gson;

/**
 * Create By IntelliJ IDEA
 *
 * @author: myq
 * @create-Time: 2017/12/7  9:38
 */
public class Alipay {
    private AlipayClient client;
    private AlipayTradePagePayRequest request;

    public Alipay(boolean shoulereturn) {
        client = AlipayFactory.getClient();
        request = new AlipayTradePagePayRequest();
        if(shoulereturn){
            AlipayFactory.setReturn(request);
        }
    }

    public Alipay(AlipayClient client, AlipayTradePagePayRequest request) {
        this.client = client;
        this.request = request;
    }

    public String execute(AlipayBase base) throws AlipayApiException {
        Gson gson = new Gson();
        String json = gson.toJson(base);
        request.setBizContent(json);
        String body = client.execute(request).getBody();
        return body;
    }
}
